

; Health Class
; restores health to players when they walk over it

(load "physics-object.scm")

(define health%
  (class physics-object%
    
    ; PHYSICS-OBJECT%
    (inherit-field position
                   collision-occured
                   collision-list)
    (inherit add-collision)
    ; PUBLIC VARIABLES
    (init-field [health *health-default*])
    ; PRIVATE VARIABLES
    (define graphics-health (new graphics-object% [graphics-name "health"]))
    (define taken #f)
    
    ; Draw
    (define/override (draw dc)
      (send graphics-health draw dc (get-x position) (get-y position)))
    
    ; Inflict Damage
    (define/public (give-health)
      ; call take-damage for each object in collision-list
      (for-each (lambda (object)
                  (when (method-in-interface? 'heal (object-interface object))
                    (send object heal health)
                    (set! taken #t)))
                collision-list))
    
    ; Collide
    (define/override (collide x y collision)
      (when (object? collision)
        (add-collision collision)))
    
    ; Update
    (define/override (update)
      (when collision-occured
        (give-health))
      (not taken))
    
    ; Constructor/Initialization
    (super-new [size (make-size graphics-health)] [solid #f])))

